package aop.common;

import java.util.Map;

import javax.annotation.Resource;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

import uri.model.board.PublicListVO;

@Aspect
public class SearchWordRankService {
	@Resource(name="searchWordRankDAOImpl")
	private SearchWordRankDAO SearchWordRankDAO;
	@Around("execution(public * uri..*Service.search*(..))")
	public Object loginMemberRank(ProceedingJoinPoint point) throws Throwable{
		String targetClass=point.getTarget().getClass().getName();
		String methodName=point.getSignature().getName();
		Object params[]=point.getArgs();
		Object retValue=null;
		try {
			retValue = point.proceed();
			if(params!=null && params.length!=0 && params[0] instanceof String  && ((Map)retValue).size()!=3){
				String searchWord=(String) params[0];
				int result=SearchWordRankDAO.isFirstSearch(searchWord);
				if(result==0){
					SearchWordRankDAO.insertSearchWord(searchWord);
				}else{
					SearchWordRankDAO.updateSearchWord(searchWord);
				}
				System.out.println("@검색어 : "+searchWord); // 전체 검색
			}
			if(params!=null && params.length!=0 && params[0] instanceof Map && ((PublicListVO)retValue).getList().size()!=0){
				String searchWord=(String)((Map) params[0]).get("word");
				int result=SearchWordRankDAO.isFirstSearch(searchWord);
				if(result==0){
					SearchWordRankDAO.insertSearchWord(searchWord);
				}else{
					SearchWordRankDAO.updateSearchWord(searchWord);
				}
				System.out.println("@검색어 : "+searchWord);
			}
		} catch (Throwable e) {
			throw e;
		} finally {
			
		}
		return retValue;
	}
}
